#ifndef QWIDGETSCRIPT_H
#define QWIDGETSCRIPT_H

#include "shared_global.h"

#include <QObject>
#include <QWidget>
#include <QVariant>

class QScriptEngine;
class tagImageInfo;

class SHAREDSHARED_EXPORT QObjectHost: public QObject
{
    Q_OBJECT
public:
    QObjectHost(QWidget* wid);
    ~QObjectHost();

    void    setGlobalObject(QObject* o);

    void    initProperty();
    void    initScript();
    void    initRunningProperty();

    void    addPropertyGroup(const QStringList &groups);
    void    addProperty(const QString& group,const QStringList &propertys);
    void    addUserProperty(const QStringList &pro);
    void    addStyleSheetGroup(const QStringList &groups);

    void    updatePropertyAttribute();
    void    updateStyle(const QString &name,bool now=true);



protected:
    void    objectMousePress(QMouseEvent* e);
    void    objectMouseMove(QMouseEvent* e);
    void    objectMouseRelease(QMouseEvent* e);
    void    objectMouseDbClick(QMouseEvent* e);

    bool    eventFilter(QObject *, QEvent *);
    void    updateStyleSheet();

    void    setImageSheet(const QString &name,tagImageInfo *info,const QString &type);
public slots:
    void    exec(const QString code, const QString &para);
    void    dataChanged(const QString &key, const QVariant &value);

    void    initGlobalObject();

    bool    visible();
    bool    enabled();

    int     x();
    int     y();
    int     width();
    int     height();
    void    setGeomerty(int x,int y,int width,int height);

    void    setToolTip(const QString &tooltip);
    QString toolTip();

    void    setProperty(const QString &name, const QVariant &value);
    QVariant property(const QString &name);

signals:
    void    setVisible(bool visible);
    void    setEnabled(bool enabled);
    void    setFocus ();

    void    showPage(const QString &page);
    void    hidePage(const QString &page);
    bool    createPage(const QString &page);
    void    close();
    void    setMemeryData(const QString &key,const QVariant &value);
    QVariant memeryData(const QString &key);
protected:
    QObject         *m_global_object;
    QScriptEngine   *m_engine;
    QWidget         *m_widget;
    QMap<QString,QString>   m_styleSheets;
};

extern SHAREDSHARED_EXPORT void qRegPropertyType(const QString &type,const QString &name,const QString &className="");
extern SHAREDSHARED_EXPORT QString propertyType(const QString &name,const QString &className);
#endif // QWIDGETSCRIPT_H
